package scripts.justj.justwintertodt.gui;

import org.apache.commons.lang3.math.NumberUtils;

import javax.swing.*;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

public class WintertodtGui extends JFrame {
  private JLabel titleLabel;
  private JLabel foodNameLabel;
  private JTextField foodNameField;
  private JTextField foodAmountField;
  private JLabel foodAmountLabel;
  private JButton startButton;
  private JPanel mainPanel;

  public WintertodtGui(String title) {
    super(title);
    this.setContentPane(mainPanel);
    this.setVisible(true);
    this.setLocationRelativeTo(null);
    this.setSize(400, 300);
    this.setResizable(false);
    startButton.addActionListener(e -> {
      Vars.getInstance().setFoodName(foodNameField.getText());
      Vars.getInstance().setFoodAmount(NumberUtils.toInt(foodAmountField.getText(), 6));
      Vars.getInstance().setGuiComplete(true);
      this.setVisible(false);
      this.dispose();
    });
  }

  {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
    $$$setupUI$$$();
  }

  /**
   * Method generated by IntelliJ IDEA GUI Designer
   * >>> IMPORTANT!! <<<
   * DO NOT edit this method OR call it in your code!
   *
   * @noinspection ALL
   */
  private void $$$setupUI$$$() {
    mainPanel = new JPanel();
    mainPanel.setLayout(new GridBagLayout());
    titleLabel = new JLabel();
    Font titleLabelFont = this.$$$getFont$$$(null, -1, 28, titleLabel.getFont());
    if (titleLabelFont != null) titleLabel.setFont(titleLabelFont);
    titleLabel.setHorizontalAlignment(0);
    titleLabel.setHorizontalTextPosition(0);
    titleLabel.setText("JustWintertodt");
    GridBagConstraints gbc;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 6;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    mainPanel.add(titleLabel, gbc);
    foodNameLabel = new JLabel();
    foodNameLabel.setEnabled(true);
    foodNameLabel.setHorizontalAlignment(0);
    foodNameLabel.setHorizontalTextPosition(0);
    foodNameLabel.setText("Food Name:");
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 1;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    mainPanel.add(foodNameLabel, gbc);
    foodNameField = new JTextField();
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.gridy = 1;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(foodNameField, gbc);
    foodAmountLabel = new JLabel();
    foodAmountLabel.setHorizontalAlignment(0);
    foodAmountLabel.setHorizontalTextPosition(0);
    foodAmountLabel.setText("Food Amount:");
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 2;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    mainPanel.add(foodAmountLabel, gbc);
    foodAmountField = new JTextField();
    gbc = new GridBagConstraints();
    gbc.gridx = 4;
    gbc.gridy = 2;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(foodAmountField, gbc);
    final JPanel spacer1 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 5;
    gbc.gridy = 1;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(spacer1, gbc);
    final JPanel spacer2 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 5;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(spacer2, gbc);
    final JPanel spacer3 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth = 2;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(spacer3, gbc);
    startButton = new JButton();
    startButton.setEnabled(true);
    Font startButtonFont = this.$$$getFont$$$(null, -1, 18, startButton.getFont());
    if (startButtonFont != null) startButton.setFont(startButtonFont);
    startButton.setText("Start Script");
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.gridwidth = 5;
    mainPanel.add(startButton, gbc);
    final JPanel spacer4 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.VERTICAL;
    mainPanel.add(spacer4, gbc);
  }

  /**
   * @noinspection ALL
   */
  private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
    if (currentFont == null) return null;
    String resultName;
    if (fontName == null) {
      resultName = currentFont.getName();
    } else {
      Font testFont = new Font(fontName, Font.PLAIN, 10);
      if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
        resultName = fontName;
      } else {
        resultName = currentFont.getName();
      }
    }
    return new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
  }

  /**
   * @noinspection ALL
   */
  public JComponent $$$getRootComponent$$$() {
    return mainPanel;
  }

}
